import { defineStore } from "pinia";
import dayjs from 'dayjs'

export const usePageStore = defineStore('page', {
    state: () => {
        return {
            clickTimeStamp: null, // 这个页面点击方法
            quality_form_id: {  // 记录查询条件回显
                platform: null,
                company: '',
                org: '',
                branch: '',
            },
            itemTagsData: [], // 质检评分信息
            calculateScore: 0, // 计算得分
            allIds: [], // 所有质检结果可以点击详情的id
            resultType: null, // 质检结果类型
            currentDetailId: null, // 当前详情id
            currentPlayTime: null, // 当前语音播放时间
            audioPlayInterval: { // 单条语音播放时间
                start: null,
                end: null
            },
            isResetQuality: false, // 详情页面是否重新质检
            isSinglePlay: false, // 判断录音是否是单条播放
            lightMenu: '', // 隐藏菜单左侧导航对应高亮
            queryResultParams: {},
            templateStatus: 0
        }
    },
    getters: {},
    actions: {
        setClickTimeStamp() {
            this.clickTimeStamp = dayjs(new Date()).unix()
        },
        setFormCondition(platform, company, org, branch) {
            this.quality_form_id.platform = platform
            this.quality_form_id.company = company
            this.quality_form_id.org = org
            this.quality_form_id.branch = branch
        },
        setItemTagsData(ary) {
            this.itemTagsData = ary
        }
    },
    persist: {
        enabled: true, // 开启数据缓存
        strategies: [
            {
                key: 'clickTimeStamp',
                storage: sessionStorage,
                paths: ["clickTimeStamp"],
            },
            {
                key: 'quality_form_id',
                storage: sessionStorage,
                paths: ["quality_form_id"],
            },
            {
                key: 'detailIdInfo',
                storage: sessionStorage,
                paths: ["allIds", 'currentDetailId', 'resultType'],
            },
            {
                key: 'lightMenu',
                storage: sessionStorage,
                paths: ['lightMenu'],
            },
            {
                key: 'queryResultParams',
                storage: sessionStorage,
                paths: ['queryResultParams'],
            }
        ]
    }
})
